package com.blacktry.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blacktry.entity.enums.OprLogConst;
import com.blacktry.entity.model.ApiResult;
import com.blacktry.entity.model.TrainingProgram;
import com.blacktry.entity.model.Vo.TrainingProgramVO;
import com.blacktry.entity.model.request.TrainingProgramRequest;
import com.blacktry.service.TrainingProgramService;
import com.blacktry.utils.ApiResultHandler;
import com.blacktry.utils.log.OperLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author blackTry
 * @since 2021-12-12
 */
@Api(value="培养计划模块模块", tags = "培养计划管理接口")
@RestController
@RequestMapping("/training-program")
public class TrainingProgramController {
    @Autowired
    private TrainingProgramService trainingProgramService;


    @OperLog(operModul = "培养计划模块模块-分页查询所有培养计划信息",operType = OprLogConst.SELECT,operDesc = "分页查询所有培养计划信息")
    @ApiOperation("分页查询所有培养计划信息")
    @PostMapping("/findAll/{page}/{size}")
    public ApiResult<Map<Integer,List<TrainingProgram>>> findAll(@RequestBody TrainingProgramRequest trainingProgramRequest, @DefaultValue("1") @PathVariable("page") Integer page, @DefaultValue("6") @PathVariable("size") Integer size) {
        System.out.println("分页查询所有培养计划信息");
        Page<TrainingProgramVO>  trainingProgramPage = new Page<>(page, size);
        return ApiResultHandler.buildApiResult(200, "请求成功！",trainingProgramService.findTrainByGrade(trainingProgramRequest,trainingProgramPage));
    }


    @OperLog(operModul = "客观题模块-查询培养计划中所有年级",operType = OprLogConst.SELECT,operDesc = "查询培养计划中所有年级")
    @ApiOperation("查询培养计划中所有年级")
    @GetMapping("/selectGrade")
    public ApiResult<List<Integer>> selectGrade(){
        System.out.println("查询培养计划中所有年级");
        return ApiResultHandler.buildApiResult(200, "请求成功！",trainingProgramService.selectGrade());
    }
}

